//--------------------------------------------------------------------------------------
// In this files we implement the methods which read all the request from the request registry and make a single post request for all of them
// It then split the single json which is returned into several object that correspond to each individual request and apply the correct function to it

//--------------------------------------------------------------------------------------
// take the json from a bag and apply the js function to it
function drawChartAndTables(response)
{ 
    var allJsonsList = eval( response.responseText );
    // for all the returned json, apply the js function to it.
    for(var i = 0; i < allJsonsList.length ;i++)
    {
        getGetJSFuncByName(allJsonsList[i].js_name)(allJsonsList[i].py_name);
    }
 };


//--------------------------------------------------------------------------------------
// call the json from the python then call the function which apply the correct js function to each json
function callJsonsFromPythonThenApplyJSFuncToThem(optionalCallbackFunc) 
{
    var args = { 
           type: "POST", 
           url: "/json/getAllJsons/", 
           cache: false, 
           data: { 'callsList' : makeCallsListAsString() }, 
           complete:function(response){
                     drawChartAndTables(response);
                     if( typeof(optionalCallbackFunc) != 'undefined' ){
                        return optionalCallbackFunc();
                     }
                     return;
                  },
           error: function(errorThrown)  { document.write(errorThrown.responseText);  }
           };
    $.ajax(args);
    return false;
};


